﻿<html>
	<head>
		<title>JSEV Test Bed</title>
		<style type="text/css">
			fieldset {
				padding: 0.5em;
				margin-top: 0.5em;
				border: 1px solid black;
				font-family: monospace;
			}
			textarea {
				width: 100%;
				height: 10em;
				border: none;
			}
			#schemaContainer div {
				width: 50%;
				float: left;
			}
			#outputContainer, #validateButton {
				clear: both;
			}
			#validateButton {
				padding-top: 0.5em;
			}
		</style>
		<script type="application/javascript" src="methods.Object.js"></script>
		<script type="application/javascript" src="methods.Array.js"></script>
		<script type="application/javascript" src="JSON.schema.reg.js"></script>
		<script type="application/javascript" src="JSON.path.js"></script>
		<script type="application/javascript" src="JSON.ref.js"></script>
		<script type="application/javascript" src="JSON.schema.err.js"></script>
		<script type="application/javascript" src="JSON.schema.err.messages.en.js"></script>
		<script type="application/javascript" src="JSON.schema.ext.walker.js"></script>
		<script type="application/javascript" src="JSON.schema.ext.js"></script>
		<script type="application/javascript">
			var schema = {};

			function validate() {
				var outEle = document.getElementById("errorOutput");
				eval("schema = " + document.getElementById("schemaToValidate").value + ";");
				JSON.schema.registry.unregister("*");
				eval(document.getElementById("schemaToRegister").value);

				var retVal = JSON.schema.ext.validate(schema);

				if (retVal.valid) {
					outEle.innerHTML = "<legend>Errors</legend>" + "No errors found!";
				} else {
					var out = "";
					for (var i in retVal.errors) {
						out += JSON.schema.err.localize('en', retVal.errors[i]) + "<br>";
					}

					outEle.innerHTML = "<legend>Errors</legend>" + out;
				}
			}
		</script>
	</head>
	<body>
		<div id="schemaContainer">
			<div>
				<fieldset>
					<legend>Schema to validate</legend>
					<textarea id="schemaToValidate"></textarea>
				</fieldset>
			</div>
			<div>
				<fieldset>
					<legend>Schemas to register</legend>
					<textarea id="schemaToRegister"></textarea>
				</fieldset>
			</div>
		</div>
		<div id="validateButton"><button onclick="validate();">Validate</button></div>

		<div id="outputContainer">
			<fieldset id="errorOutput">
				<legend>Errors</legend>
			</fieldset>
		</div>
	</body>
</html>